package org.jsbd.boss.action;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.jsbd.boss.domian.UserOptLog;
import org.jsbd.boss.service.impl.UserOptService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/useropt")
public class UserOptController {
	public static final Logger LOGGER = LoggerFactory.getLogger(UserOptController.class);

	@Autowired
	private UserOptService userOptService;

	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public String configList(Model model) {
		return "useropt/configList";
	}

	// 基本配置查询展示接口
	@RequestMapping(value = "/configList", params = "json")
	@ResponseBody
	public Map<String, Object> configPageList(HttpServletRequest request, UserOptLog userOptLog) {
		String currDate = userOptLog.getCurrentDate();
		if(StringUtils.isNotBlank(currDate)){
			currDate = currDate.replaceAll("-", "");
			userOptLog.setCurrentDate(currDate);
		}else {
			currDate = edu.hziee.common.lang.DateUtil.formatDate(new Date(), "yyyyMMdd");
			userOptLog.setCurrentDate(currDate);
		}
		List<UserOptLog> list= userOptService.getAllUserOpt(userOptLog);
		int total = userOptService.selectCount(userOptLog);
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("rows", list);
		map.put("total", total);
		return map;
	}
	
	@RequestMapping(value = "/keywordInfo", method = RequestMethod.GET)
	public String info(Model model) {
		return "useropt/keywordInfo";
	}
}
